﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  System.Data.Entity;
using EF5;

namespace DataContextLayer
{
	public class DclContext:DbContext
	{
		public DbSet<User> Users { get; set; }
		public DbSet<Tutorial> Tutorials { get; set; }
		public DbSet<Achievement> Achievments { get; set; }
		public DbSet<AchievementEarned> AchievementEarneds { get; set; } 

	}

    public class ContactsInitialzer : DropCreateDatabaseAlways<DclContext>
    {
        protected override void Seed(DclContext context)
        {
            var users = new List<User>
                             {
                                new User{UserId=1,UserEmail = "nbanko@yahoo.com",UserName = "nbanko",UserPassword = "6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0},
                                new User{UserId=2,UserEmail="jam@reerr.net",UserName = "jmass",UserPassword="6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0},
                                new User{UserId=3,UserEmail = "louis.chilson@gmail.com",UserName="evan",UserPassword = "6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0},
                                new User{UserId=4,UserEmail = "zeeeeke@target.net",UserName="zeke",UserPassword = "6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0},
                                new User{UserId=5,UserEmail = "McCracken@test.edu",UserName = "Cracken",UserPassword = "6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0},
                                new User{UserId=6,UserEmail = "devry@devry.net",UserName ="ftWashington",UserPassword = "6Pl/upEE0epQR5SObftn+s2fW3M=",UserPasswordReset=false,UserAcountLocked = false,FailedLoginAttempts = 0}
                                            
                             };
            foreach (User user in users)
            {
                context.Users.Add(user);
                context.SaveChanges();

            }

            var tutorials = new List<Tutorial>
                          {
                             new Tutorial{TutorialId = 1,TutorialLanguage="c#", TutorialName="for loop",TutorialCompleted = false,TutorialStarted =DateTime.Today, UserId = 3},
                              new Tutorial{TutorialId = 4,TutorialLanguage="c#", TutorialName="int",TutorialCompleted = false,TutorialStarted =DateTime.Now, UserId = 3},
                              new Tutorial{TutorialId = 2,TutorialLanguage="c#",TutorialName="string",TutorialCompleted = true,TutorialStarted = Convert.ToDateTime("9/22/2012 12:00:00"), UserId=3},
                              new Tutorial{TutorialId = 3,TutorialLanguage="c#",TutorialName="random",TutorialCompleted = true,TutorialStarted = Convert.ToDateTime("9/24/2012 12:00:00"), UserId=3},
                              new Tutorial{TutorialId = 5,TutorialLanguage="java",TutorialName="string",TutorialCompleted = true,TutorialStarted = Convert.ToDateTime("9/22/2012 12:00:00"), UserId=3},
                              new Tutorial{TutorialId = 6,TutorialLanguage="f",TutorialName="random",TutorialCompleted = true,TutorialStarted = Convert.ToDateTime("9/24/2012 12:00:00"), UserId=3}
                              
                          };
            foreach (Tutorial tutorial in tutorials)
            {
                context.Tutorials.Add(tutorial);
                context.SaveChanges();

            }

            var achievements = new List<Achievement>
                          {
                              new Achievement{AchievementId = 1,AchievementTitle = "Getting started",AchievementDescription = "created an account",AchievementPoints = 10},
                              new Achievement{AchievementId=2,AchievementTitle = "Why reinvent the wheel",AchievementDescription = "Generate your first snippet",AchievementPoints=10},
                              new Achievement{AchievementId=3,AchievementTitle = "Start at the beginning",AchievementDescription="Complete your first tutorial",AchievementPoints = 10},
                              new Achievement{AchievementId=4,AchievementTitle = "Did your forget something?",AchievementDescription = "Lock your account out",AchievementPoints = 10},
                              new Achievement{AchievementId=5,AchievementTitle = "Extra sharp",AchievementDescription="Complete all of the c# tutorials",AchievementPoints=50}    
                          };
            foreach (Achievement achievement in achievements)
            {
                context.Achievments.Add(achievement);
                context.SaveChanges();
            }

            var achievementsEarned = new List<AchievementEarned>
                          {
                              new AchievementEarned {AchievmentId = 1, UserId = 3},
                              new AchievementEarned {AchievmentId = 2, UserId = 3},
                              new AchievementEarned {AchievmentId = 3, UserId = 3},
                              new AchievementEarned {AchievmentId = 4, UserId = 3},
                              new AchievementEarned {AchievmentId = 5, UserId = 3}
                          };
            foreach (AchievementEarned achievementEarned in achievementsEarned)
            {
                context.AchievementEarneds.Add(achievementEarned);
                context.SaveChanges();
            }


            base.Seed(context);

        }
    }
}




	

